package com.shawn.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shawn.dubbo.mapper.QuestionMapper;
import com.shawn.model.entity.Question;
import com.shawn.model.entity.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi{

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question getQuestionByUserId(Long userId) {
        LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Question::getUserId,userId);
        return questionMapper.selectOne(wrapper);
    }

    @Override
    public void updateByUserId(Question question) {
        LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Question::getUserId,question.getUserId());
        questionMapper.update(question,wrapper);
    }

    /**
     * 插入默认问题
     *
     * @param defaultQuestion 违约问题
     */
    @Override
    public void insertDefaultQuestion(Question defaultQuestion) {
        questionMapper.insert(defaultQuestion);
    }
}
